//1.队列
class Solution {
public:
    vector<vector<int>> levelOrder(TreeNode* root) {
        if(root == nullptr)
            return {};

        vector<vector<int>> ret;
        queue<TreeNode*> q;
        q.push(root);

        while(!q.empty()) {
            int size = q.size(); //当前层的节点个数
            vector<int> act;
            for(int i =0; i < size; ++i) {   //对当前层所有节点进行遍历
                auto node = q.front();  q.pop();
                act.push_back(node->val);    
                if(node->left) q.push(node->left);
                if(node->right) q.push(node->right);
            }
            ret.push_back(act);

        }
        return ret;
    }
};